import { IsOptional, IsNumber, Min, Max, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export class PaginationDto {
  @ApiProperty({ description: '页码', required: false, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页数量', required: false, default: 10 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  @Max(100)
  pageSize?: number = 10;
}

export class SearchDto extends PaginationDto {
  @ApiProperty({ description: '关键词搜索', required: false })
  @IsOptional()
  @IsString()
  keyword?: string;

  @ApiProperty({ description: '创建时间开始（YYYY-MM-DD）', required: false })
  @IsOptional()
  @IsString()
  createTimeStart?: string;

  @ApiProperty({ description: '创建时间结束（YYYY-MM-DD）', required: false })
  @IsOptional()
  @IsString()
  createTimeEnd?: string;

  @ApiProperty({ description: '排序字段', required: false })
  @IsOptional()
  @IsString()
  sortBy?: string;

  @ApiProperty({ description: '排序方向', required: false, enum: ['ASC', 'DESC'], default: 'DESC' })
  @IsOptional()
  @IsString()
  sortOrder?: 'ASC' | 'DESC' = 'DESC';
}

export interface PaginationResult<T> {
  list: T[];
  total: number;
  page: number;
  pageSize: number;
}